# -*- mode: python -*-

Import("env")

env.Library(
    target='query_planner',
    source=[
        "canonical_query.cpp",
        "query_settings.cpp",
        "index_tag.cpp",
        "parsed_projection.cpp",
        "plan_cache.cpp",
        "plan_enumerator.cpp",
        "planner_access.cpp",
        "planner_analysis.cpp",
        "planner_ixselect.cpp",
        "query_knobs.cpp",
        "query_planner.cpp",
        "query_solution.cpp",
    ],
    LIBDEPS=[
        "index_bounds",
        "lite_parsed_query",
        "$BUILD_DIR/mongo/bson",
        "$BUILD_DIR/mongo/expressions",
        "$BUILD_DIR/mongo/index_names",
        "$BUILD_DIR/mongo/server_parameters",
    ],
)

env.Library(
    target='query',
    source=[
        "cached_plan_runner.cpp",
        "eof_runner.cpp",
        "explain_plan.cpp",
        "get_runner.cpp",
        "idhack_runner.cpp",
        "internal_runner.cpp",
        "multi_plan_runner.cpp",
        "new_find.cpp",
        "plan_executor.cpp",
        "plan_ranker.cpp",
        "single_solution_runner.cpp",
        "stage_builder.cpp",
        "subplan_runner.cpp",
        "type_explain.cpp",
    ],
    LIBDEPS=[
        "query_planner",
        "query_planner_test_lib",
        "$BUILD_DIR/mongo/db/exec/exec"
    ],
)

env.CppUnitTest(
    target="get_runner_test",
    source=[
        "get_runner_test.cpp"
    ],
    LIBDEPS=[
        "query",
        "$BUILD_DIR/mongo/serveronly",
        "$BUILD_DIR/mongo/coreserver",
        "$BUILD_DIR/mongo/coredb",
        "$BUILD_DIR/mongo/mocklib",
    ],
    NO_CRUTCH = True,
)

env.Library(
    target="index_bounds",
    source=[
        "index_bounds.cpp",
        "index_bounds_builder.cpp",
        "interval.cpp",
    ],
    LIBDEPS=[
        "query_logger",
        "$BUILD_DIR/mongo/bson",
        "$BUILD_DIR/mongo/expressions_geo",
        "$BUILD_DIR/mongo/index_names",
        "$BUILD_DIR/mongo/mongohasher",
    ],
)

env.Library(
    target="lite_parsed_query",
    source=[
        "lite_parsed_query.cpp"
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/bson",
    ],
)

env.Library(
    target="query_planner_test_lib",
    source=[
        "query_planner_test_lib.cpp",
    ],
    LIBDEPS=[
        "query_planner",
    ],
)

env.Library(
    target="query_logger",
    source=[
        "qlog.cpp"
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/server_parameters",
    ],
)

env.CppUnitTest(
    target="canonical_query_test",
    source=[
        "canonical_query_test.cpp"
    ],
    LIBDEPS=[
        "query_planner",
        "$BUILD_DIR/mongo/expressions_text",
    ],
)

env.CppUnitTest(
    target="index_bounds_test",
    source=[
        "index_bounds_test.cpp"
    ],
    LIBDEPS=[
        "index_bounds",
    ],
)

env.CppUnitTest(
    target="index_bounds_builder_test",
    source=[
        "index_bounds_builder_test.cpp"
    ],
    LIBDEPS=[
        "index_bounds",
    ],
)

env.CppUnitTest(
    target="interval_test",
    source=[
        "interval_test.cpp"
    ],
    LIBDEPS=[
        "index_bounds",
    ],
)

env.CppUnitTest(
    target="lite_parsed_query_test",
    source=[
        "lite_parsed_query_test.cpp"
    ],
    LIBDEPS=[
        "lite_parsed_query",
    ],
)

env.CppUnitTest(
    target="lru_key_value_test",
    source=[
        "lru_key_value_test.cpp",
    ],
    LIBDEPS=[
    ],
)

env.CppUnitTest(
    target="parsed_projection_test",
    source=[
        "parsed_projection_test.cpp"
    ],
    LIBDEPS=[
        "query_planner",
    ],
)

env.CppUnitTest(
    target="plan_cache_test",
    source=[
        "plan_cache_test.cpp"
    ],
    LIBDEPS=[
        "query_planner_test_lib",
    ],
)

env.CppUnitTest(
    target="planner_analysis_test",
    source=[
        "planner_analysis_test.cpp"
    ],
    LIBDEPS=[
        "query_planner",
    ],
)

env.CppUnitTest(
    target="planner_ixselect_test",
    source=[
        "planner_ixselect_test.cpp"
    ],
    LIBDEPS=[
        "query_planner",
    ],
)

env.CppUnitTest(
    target="query_planner_test",
    source=[
        "query_planner_test.cpp"
    ],
    LIBDEPS=[
        "query_planner_test_lib",
    ],
)

# $text pulls in a lot of stuff so we test it here.
env.CppUnitTest(
    target="query_planner_text_test",
    source=[
        "query_planner_text_test.cpp"
    ],
    LIBDEPS=[
        "query",
        "query_planner_test_lib",
        "$BUILD_DIR/mongo/serveronly",
        "$BUILD_DIR/mongo/coreserver",
        "$BUILD_DIR/mongo/coredb",
        "$BUILD_DIR/mongo/mocklib",
    ],
    NO_CRUTCH = True,
)
